package avicit.bdp.dds.api.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.dds.dao.entity.ProcessResourceSettings;
import avicit.bdp.dds.dao.entity.SparkConfig;
import avicit.bdp.dds.dao.mapper.ProcessResourceConfigMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProcessResourceConfigService extends BaseService<ProcessResourceConfigMapper, ProcessResourceSettings> {

    @Value("${bdp.redis.host}")
    private String redisHost;
    @Value("${bdp.redis.port}")
    private String redisPort;
    @Value("${bdp.redis.password}")
    private String redisPassword;

    /**
     * 根据流程定义ID查询资源配置
     *
     * @param processDefinitionId 流程定义ID
     * @return 资源配置
     */
    public List<ProcessResourceSettings> getByProcessDefinitionId(String processDefinitionId) {
        return this.mapper.getByProcessDefinitionId(processDefinitionId);
    }

    public void deleteByProcessDefinitionId(String processDefinitionId) {
        this.mapper.deleteByProcessDefinitionId(processDefinitionId);
    }

    public SparkConfig getSparkConfigByProcessDefinitionId(String processDefinitionId) {
        ProcessResourceSettings entity = this.mapper.getSparkConfigByProcessDefinitionId(processDefinitionId);
        if (entity != null) {
            return entity.getSparkConfig();
        }
        return null;
    }

    public Map<String, String> getRedisConfig() {
        Map<String, String> map = new HashMap<>(4);
        map.put("redisHost", redisHost);
        map.put("redisPort", redisPort);
        map.put("redisPassword", redisPassword);
        return map;
    }

}
